import {
	isString
} from "@/codecat/utils/validate.js";
// 表格列字母
export const letter = new Array(
	"A",
	"B",
	"C",
	"D",
	"E",
	"F",
	"G",
	"H",
	"I",
	"J",
	"K",
	"L",
	"M",
	"N",
	"O",
	"P",
	"Q",
	"R",
	"S",
	"T",
	"U",
	"V",
	"W",
	"X",
	"Y",
	"Z"
);

/**
 * 一周排期
 */
export const weekDayOptions = [{
		label: "星期一",
		value: "1",
	},
	{
		label: "星期二",
		value: "2",
	},
	{
		label: "星期三",
		value: "3",
	},
	{
		label: "星期四",
		value: "4",
	},
	{
		label: "星期五",
		value: "5",
	},
	{
		label: "星期六",
		value: "6",
	},
	{
		label: "星期日",
		value: "7",
	},
];
// 请选择招生状态
export const recruitStatusOptions = [{
		type: "primary",
		value: 1,
		label: "开班中"
	},
	{
		type: "warning",
		value: 2,
		label: "满班停止"
	},
	{
		type: "error",
		value: 0,
		label: "停止招生"
	},
];
export const getRecruitStatus = (value) => {
	if (value !== undefined) {
		return recruitStatusOptions.find((e) => e.value === value) || null;
	} else return null;
};

export const ruleTypeOptions = [{
		label: "重复排课",
		value: 1,
		type: "primary",
	},
	{
		label: "自由排课",
		value: 2,
		type: "warning",
	},
];
export const getRuleType = (value) => {
	if (value !== undefined) {
		return ruleTypeOptions.find((e) => e.value === value) || null;
	} else return null;
};
export const repeatTypeOptions = [{
		label: "每周重复",
		value: 1,
	},
	{
		label: "隔天重复",
		value: 2,
	},
	{
		label: "隔周重复",
		value: 3,
	},
];
export const getRepeatType = (value) => {
	if (value !== undefined) {
		return repeatTypeOptions.find((e) => e.value === value) || null;
	} else return null;
};
export const studentCourseStatusOptions = [{
		label: "失效",
		value: 0,
		type: "info",
	},
	{
		label: "在读",
		value: 1,
		type: "success",
	},
	{
		label: "停课",
		value: 2,
		type: "warning",
	},
	{
		label: "结课",
		value: 3,
		type: "info",
	},
];

// "出勤类型 0原班上课，1插班补课，2插班试听 3临时学员"
export const attendType = [{
		label: "原班上课",
		value: 0,
		type: 'primary'
	},
	{
		label: "插班补课",
		value: 1,
		type: 'warning'
	},
	{
		label: "插班试听",
		value: 2,
		type: 'warning'
	}, {
		label: "临时学员",
		value: 3,
		type: 'warning'
	},
];
export const getAttendType = (value) => {
	if (value !== undefined) {
		return attendType.find((e) => e.value === value)?.label || "未知";
	} else return "未知";
};

// 到课状态1:到课 2:请假 3:缺勤
export const attendStatus = [{
		label: "到课",
		value: 1,
		type: "primary",
	},
	{
		label: "请假",
		value: 2,
		type: "warning",
	},
	{
		label: "缺勤",
		value: 3,
		type: "error",
	},
];
export const getAttendStatus = (status) => {
	if (status !== undefined) {
		return attendStatus.find((e) => e.value === status) || null;
	} else return null;
};

// 补课状态
export const remedialStatus = [{
		label: "未安排",
		value: 0,
		type: "info",
	},
	{
		label: "已安排",
		value: 1,
		type: "success",
	},
	{
		label: "已补课",
		value: 2,
		type: "success",
	},
	{
		label: "已请假",
		value: 3,
		type: "warning",
	},
	{
		label: "已缺课",
		value: 4,
		type: "error",
	},
	{
		label: "无需补课",
		value: 5,
		type: "info",
	},
];
// 补课状态 0未安排，1已安排，2已补课，3无需补课
export const getRemedialStatus = (status) => {
	if (status !== undefined) {
		return remedialStatus.find((e) => e.value === status) || null;
	} else return null;
};

/**
 * 获取学员课程状态
 */
export const getStudentCourseStatus = (status) => {
	if (status !== undefined) {
		return studentCourseStatusOptions.find((e) => e.value === status) || null;
	} else return null;
};

export const sexOptions = [{
		label: "未知",
		value: 0,
		icon: "",
	},
	{
		label: "男",
		value: 1,
		icon: "el-icon-male",
	},
	{
		label: "女",
		value: 2,
		icon: "el-icon-female",
	},
];
export const getSex = (value) => {
	if (value !== undefined) {
		return sexOptions.find((e) => e.value === value)?.label || "未知";
	} else return "未知";
};
export const getSexValue = (value) => {
	if (value !== undefined) {
		return sexOptions.find((e) => e.label === value)?.value || null;
	} else return null;
};
export const getSexIcon = (value) => {
	if (value !== undefined) {
		return sexOptions.find((e) => e.value === value)?.icon || null;
	} else return null;
};

// 排课-是否过滤
export const filterHolidayOptions = [{
		label: "过滤节假日",
		value: 1,
		type: "error",
	},
	{
		label: "不过滤节假日",
		value: 0,
		type: "primary",
	},
];
export const getFilterHoliday = (value) => {
	if (value !== 0 && value) {
		return filterHolidayOptions.find((e) => e.value === value) || null;
	} else return null;
};
// 授课模式
export const teachingType = [{
		value: 1,
		label: "班级授课",
		classTime: "班级",
		classTimeDesc: "班级排课",
		teaching_type: 1, // 为了兼容模式icon组件
	},
	{
		value: 2,
		label: "1对N",
		classTime: "1对N",
		classTimeDesc: "1对N排课",
		teaching_type: 2, // 为了兼容模式icon组件
	},
];
/**
 * 报价单模式
 * hour=按课时，date=按时间，cycle=按周期
 * cnt=数量，totalFee=总费用，dateType=时间段
 */
export const feeMode = [{
		value: "hour",
		label: "按课时",
		unit: "课时",
		tooltip: "按“购买课时数”定价，以课时为单位计费",
		type: 'primary',
		column: [{
				prop: "cnt",
				label: "数量(课时)",
			},
			{
				prop: "totalFee",
				label: "总价金额(元)",
			},
		],
		demo: {
			cnt: 1,
			totalFee: null,
		},
		error: {
			show: false,
			msg: "",
		},
	},
	{
		value: "date",
		label: "按时段",
		unit: "(时段)",
		tooltip: "按“天/自然月/自然年”定价，以“天”为单位计费",
		type: 'success',
		column: [{
				prop: "dateType",
				label: "计价方式",
			},
			{
				prop: "cnt",
				label: "数量",
			},
			{
				prop: "totalFee",
				label: "总价金额(元)",
			},
		],
		demo: {
			cnt: 1,
			dateType: "day", // 天、月、季、年
			totalFee: null,
		},
		error: {
			show: false,
			msg: "",
		},
	},
];

/**
 * 获取当前订单明细内容的描述
 */
export const getFeeModeLabel = (fee_mode) => {
	if (isString(fee_mode)) {
		fee_mode = JSON.parse(fee_mode);
	}
	let content = "";
	const {
		dateType,
		cnt,
		totalFee,
		mode
	} = fee_mode;
	if (mode === "date") {
		const {
			label
		} = getDateTypeItem(dateType);
		content = `${cnt} ${label} | ${totalFee}元`;
	} else {
		const {
			unit
		} = getFeeModeItem(mode);
		content = `${cnt} ${unit} | ${totalFee}元`;
	}
	return content;
};

/**
 * 年数	y
 * 季度	Q
 * 月数	M
 * 天数	d
 */
export const dateTypeOptions = [{
		value: "day",
		label: "天",
		code: "d",
	},
	{
		value: "month",
		label: "月",
		code: "M",
	},
	// {
	//   value: "season",
	//   label: "季",
	//   code: "Q",
	// },
	{
		value: "year",
		label: "年",
		code: "y",
	},
];

// follow_status 跟进状态 0=待跟进，1=跟进中，2=已邀约，3=已试听
export const followStatus = [{
		value: 0,
		label: "待跟进",
		type: "error",
	},
	{
		value: 1,
		label: "跟进中",
		type: "primary",
	},
	{
		value: 2,
		label: "已邀约",
		type: "warning",
	},
	{
		value: 3,
		label: "已试听",
		type: "success",
	},
];

// 关系表
export const contactRelationOptions = [{
		label: "本人",
		value: "self",
	},
	{
		label: "妈妈",
		value: "mommy",
	},
	{
		label: "爸爸",
		value: "daddy",
	},
	// {
	//   label: "爷爷",
	//   value: "yy",
	// },
	// {
	//   label: "奶奶",
	//   value: "nn",
	// },
	// {
	//   label: "姥爷",
	//   value: "ly",
	// },
	// {
	//   label: "姥姥",
	//   value: "ll",
	// },
	{
		label: "其他",
		value: "other",
	},
];

// 潜在学员的人员状态
export const intentionStudentStatus = [{
		label: "在读学员",
		name: "在读学员",
		value: 1,
		type: "primary",
		prop: 'status_1', // 这是对应后端返回的参数
	},
	{
		label: "潜在学员",
		name: "潜在学员",
		value: 0,
		type: "warning",
		prop: 'status_0', // 这是对应后端返回的参数
	},
	{
		label: "历史学员",
		name: "历史学员",
		value: 2,
		type: "info",
		prop: 'status_2', // 这是对应后端返回的参数
	},
];
export const getStudentStatus = (status) => {
	if (status !== undefined) {
		return intentionStudentStatus.find((e) => e.value === status) || null;
	} else return null;
};

// 意向度 ['低', '中', '高']
export const intentionLevel = [{
		label: "低",
		value: 0,
		type: "info",
	},
	{
		label: "中",
		value: 1,
		type: "primary",
	},
	{
		label: "高",
		value: 2,
		type: "error",
	},
];

// 跟进方式 0无 1电话 2面谈 3其他
export const followType = [{
		label: "电话",
		value: 1,
	},
	{
		label: "面谈",
		value: 2,
	},
	{
		label: "其他",
		value: 3,
	},
];

// 试听类型 "audition_type": "试听类型 0免费试听 1付费试听",
export const auditionType = [{
		label: "免费试听",
		value: 0,
	},
	{
		label: "付费试听",
		value: 1,
	},
];

// 试听状态 "status": "试听状态 0已邀约 1已试听 2已转化 3已取消"
export const auditionStatus = [{
		label: "已邀约",
		value: 0,
		type: "primary",
	},
	{
		label: "已试听",
		value: 1,
		type: "success",
	},
	{
		label: "已取消",
		value: 2,
		type: "info",
	},
	{
		label: "已缺勤",
		value: 3,
		type: "error",
	},
];
export const getAuditionStatus = (value) => {
	if (value !== undefined) {
		return auditionStatus.find((e) => e.value === value) || null;
	} else return null;
};
// 回访状态
export const visitStatus = [{
		label: "未回访",
		value: 0,
		type: "info",
	},
	{
		label: "已回访",
		value: 1,
		type: "success",
	},
];

// order_type=订单类型0报读，1退费
// 订单类型
export const orderType = [{
		label: "报读",
		value: 0,
		type: "error",
		tag: "收",
	},
	{
		label: "退费",
		value: 1,
		type: "success",
		tag: "退",
	},
];
export const getOrderType = (value) => {
	if (value !== undefined) {
		return orderType.find((e) => e.value === value) || null;
	} else return null;
};

// 报读类型
export const orderTags = [{
		label: "新报",
		value: 1,
	},
	{
		label: "续报",
		value: 2,
	},
];
export const getOrderTags = (value) => {
	if (value !== undefined) {
		return orderTags.find((e) => e.value === value)?.label || "-";
	} else return "-";
};
// 订单产品类型
export const orderDetailTags = [{
		label: "课程",
		value: 1,
	},
	{
		label: "商品",
		value: 2,
	},
];





// 0待支付 1欠款 2已支付 3已作废
export const orderStatus = [{
		label: "待支付",
		value: 0,
		type: "error",
	},
	{
		label: "欠款",
		value: 1,
		type: "warning",
	},
	{
		label: "完成支付",
		value: 2,
		type: "success",
	},
	{
		label: "已作废",
		value: 3,
		type: "info",
	},
];
export const getOrderStatus = (status) => {
	if (status !== undefined) {
		return orderStatus.find((e) => e.value === status) || {};
	} else return {};
};

export const claTimeContainer = Object.freeze([{
		time: "08:00 ~ 10:00",
		claTimeWeekDayMap: {
			1: [],
			2: [],
			3: [],
			4: [],
			5: [],
			6: [],
			7: []
		},
	},
	{
		time: "10:00 ~ 12:00",
		claTimeWeekDayMap: {
			1: [],
			2: [],
			3: [],
			4: [],
			5: [],
			6: [],
			7: []
		},
	},
	{
		time: "12:00 ~ 14:00",
		claTimeWeekDayMap: {
			1: [],
			2: [],
			3: [],
			4: [],
			5: [],
			6: [],
			7: []
		},
	},
	{
		time: "14:00 ~ 16:00",
		claTimeWeekDayMap: {
			1: [],
			2: [],
			3: [],
			4: [],
			5: [],
			6: [],
			7: []
		},
	},
	{
		time: "16:00 ~ 18:00",
		claTimeWeekDayMap: {
			1: [],
			2: [],
			3: [],
			4: [],
			5: [],
			6: [],
			7: []
		},
	},
	{
		time: "18:00 ~ 20:00",
		claTimeWeekDayMap: {
			1: [],
			2: [],
			3: [],
			4: [],
			5: [],
			6: [],
			7: []
		},
	},
	{
		time: "20:00 ~ 22:00",
		claTimeWeekDayMap: {
			1: [],
			2: [],
			3: [],
			4: [],
			5: [],
			6: [],
			7: []
		},
	},
]);

export const columnTitles = Object.freeze([{
		day: "-",
		count: "-",
		weekName: "星期一",
	},
	{
		day: "-",
		count: "-",
		weekName: "星期二",
	},
	{
		day: "-",
		count: "-",
		weekName: "星期三",
	},
	{
		day: "-",
		count: "-",
		weekName: "星期四",
	},
	{
		day: "-",
		count: "-",
		weekName: "星期五",
	},
	{
		day: "-",
		count: "-",
		weekName: "星期六",
	},
	{
		day: "-",
		count: "-",
		weekName: "星期日",
	},
]);
export const weeks = ["日", "一", "二", "三", "四", "五", "六"];
export const getWeek = (date) => {
	if (date !== undefined) {
		return weeks[new Date(date).getDay()] || null;
	} else return null;
};

export const getRelation = (contact_relation) => {
	if (contact_relation !== undefined) {
		return (
			contactRelationOptions.find((e) => e.value === contact_relation)?.label ||
			"未知"
		);
	} else return "未知";
};

/**
 * 课程信息：如果课程按时间的，获取时间单位（天月季年）
 * @param {*} data_type
 * @returns
 */
export const getDateType = (data_type) => {
	if (data_type !== undefined) {
		return dateTypeOptions.find((e) => e.value === data_type)?.label || "";
	} else return "";
};
export const getDateTypeItem = (data_type) => {
	if (data_type !== undefined) {
		return dateTypeOptions.find((e) => e.value === data_type) || {};
	} else return {};
};
/**
 * 课程信息：获取课程计算模式
 */
export const getFeeMode = (value) => {
	if (value !== undefined) {
		return feeMode.find((e) => e.value === value)?.label || "-";
	} else return "-";
};

export const getFeeModeItem = (value) => {
	if (value !== undefined) {
		return feeMode.find((e) => e.value === value) || null;
	} else return null;
};

/**
 * 课程信息：获取课程计算数量
 * @param {*} mode
 * @returns
 */
export const getFeeModeUnit = (mode, data_type) => {
	if (mode !== undefined) {
		const item = feeMode.find((e) => e.value === mode);
		if (mode === "date") {
			return getDateType(data_type);
		} else return item?.unit || "";
	} else return "";
};

export const leaveStatus = [
	// 状态 0未审批 1已审批 2已拒绝 3已取消
	{
		value: 0,
		label: "未审批",
		type: "warning"
	},
	{
		value: 1,
		label: "已审批",
		type: "success"
	},
	{
		value: 2,
		label: "已拒绝",
		type: "info"
	},
	{
		value: 3,
		label: "已取消",
		type: "error"
	},
];

export const getLeaveStatus = (status) => {
	if (status !== undefined) {
		return leaveStatus.find((e) => e.value === status) || {};
	} else return {};
};

// 状态 0:待上课 1:已上课 2:已取消
// 日程状态
export const classCourseStatus = [{
		value: 0,
		label: "待上课",
		type: "info"
	},
	{
		value: 1,
		label: "已上课",
		type: "success"
	},
	{
		value: 2,
		label: "已取消",
		type: "info"
	},
];
export const getClassCourseStatus = (status) => {
	if (status !== undefined) {
		return classCourseStatus.find((e) => e.value === status) || {};
	} else return {};
};

/**
 * 对话状态
 * 问题状态 0客服未回复 1客服已回复，等待用户回复 2用户已回复，等待客服回复 3已解决
 */
export const issueStatus = [{
		label: "客服未回复",
		value: 0,
	},
	{
		label: "客服已回复，等待用户回复",
		value: 1,
	},
	{
		label: "用户已回复，等待客服回复",
		value: 2,
	},
	{
		label: "已解决",
		value: 3,
	},
];
export const getIssueStatus = (value) => {
	return issueStatus.find((e) => e.value === value)?.label || "-";
};

//
export const expendType = [{
		label: "点名消耗",
		value: 0,
		type: "primary",
	},
	{
		label: "日期消耗",
		value: 1,
		type: "primary",
	},
	{
		label: "结课消耗",
		value: 2,
		type: "primary",
	},
];
export const getExpendType = (value) => {
	return expendType.find((e) => e.value === value)?.label || "-";
};


const Dict = {
	'followType': followType,
	'intentionLevel': intentionLevel,
	'visitStatus': visitStatus,
	'auditionType': auditionType,
	'auditionStatus': auditionStatus,
	'contactRelationOptions': contactRelationOptions,
	"intentionStudentStatus": intentionStudentStatus,
	'teachingType': teachingType,
	'feeMode': feeMode,
	'dateTypeOptions': dateTypeOptions,
	'studentCourseStatusOptions': studentCourseStatusOptions,
	"attendType": attendType,
	"attendStatus": attendStatus,
	"orderTags": orderTags,
	"orderStatus": orderStatus,
	"recruitStatusOptions": recruitStatusOptions,
	"classCourseStatus": classCourseStatus,
	"remedialStatus": remedialStatus,
	"leaveStatus": leaveStatus,
	"filterHolidayOptions": filterHolidayOptions,
	"repeatTypeOptions": repeatTypeOptions,
	"followStatus": followStatus,
	"sexOptions": sexOptions,
	"orderType": orderType
}

/**
 * 本地获取字典公共方法
 * @param {String} key - 对应【Dict】的key
 * @param {String | Number} value - 查询的值
 */
export function getDict(key, value) {
	if (!key || value === undefined || value === null) return {}
	return Dict[key].find((e) => e.value === value) || {};
};